package com.ayu.wxgzh.ayucyy.chain.handler;

import com.ayu.wxgzh.ayucyy.Utils.AccessTokenUtils;
import com.ayu.wxgzh.ayucyy.entity.BaseMessage;
import com.ayu.wxgzh.ayucyy.entity.TextMessage;
import com.ayu.wxgzh.ayucyy.service.EmojiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @Author 徐林玉
 * @Description EmojiHandler
 * @Date 2023/2/3 13:34
 * @Version 1.0
 */

@Component
@Slf4j
public class EmojiHandler extends AbstractHandler {


    @Value("${crawler.win.path:}")
    private String winPath;

    @Value("${crawler.linux.path:}")
    private String linuxPath;


    private final EmojiService emojiService;

    @Autowired
    public EmojiHandler(EmojiService emojiService) {
        this.emojiService = emojiService;
    }

    @Override
    public BaseMessage handle(Map<String, String> requestMap) {

        //降级：如果配置了降级，则跳过此处理器，执行下一个处理器
        if (super.getConfig().getDown()) {
            log.warn("表情包下载 EmojiHandler 已降级，跳过表情包下载 EmojiHandler...");
            return super.next(requestMap);
        }

        TextMessage textMessage = null;
        try {
            textMessage = emojiService.getEmojiUrl(requestMap);
        } catch (ExecutionException | InterruptedException e) {
            log.error(e.getMessage());
        }
        if (textMessage != null) {
            return textMessage;
        }



        return super.next(requestMap);
    }
}
